package com.kyrioscraft.cloud.thead.jdklab.tools.collections;

import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Author kyrioscraft
 * @Date 2019/2/19 15:55
 * @Description //TODO
 **/
public class SimpleDemo {
    //把new的对象赋值给mutex成为synchronized锁对象,读取和写入都需要获得锁,并发级别不高
    public static Map m = Collections.synchronizedMap(new HashMap<>());

    //高性能线程安全，Entry数组分段，顺序对段加锁和解锁，段冲突时各段连表
    public static ConcurrentHashMap map = new ConcurrentHashMap();

    //Vector是线程俺去的，LinkeList线程安全使用Collections工具包装
    public static List<String> l = Collections.synchronizedList(new LinkedList<String>());

    public static void main(String[] args) throws InterruptedException{
        ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(10);
        queue.offer("string2");//放满时不阻塞
        queue.put("string1");//await关键字,当队列为空时线程阻塞
        queue.poll();//队列为空时返回null
        queue.take();//await关键字,当队列为空时线程阻塞
        LinkedBlockingDeque<String> linkedBlockingDeque = new LinkedBlockingDeque<>();

    }
}
